package com.example.bannerstuday;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private Banner banner;
    private RecyclerView recyclerView;
    private ArrayList<getInformation> list = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        addInformation();
        banner = findViewById(R.id.banner);
        banner.setAdapter(new BannerImageAdapter<DataBean>(DataBean.getTestData3()) {

            @Override
            public void onBindView(BannerImageHolder holder, DataBean data, int position, int size) {
                Glide.with(holder.itemView)
                        .load(data.imageUrl)
                        .into(holder.imageView);
            }
        })
                .addBannerLifecycleObserver(this)//添加生命周期观察者
                .setIndicator(new CircleIndicator(this));
    }

    public void initView(){
        recyclerView = findViewById(R.id.recyclerview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(new myAdapter(list,R.layout.everyitem));

    }
    public void addInformation(){
       for (int i =0;i<10;i++){
           getInformation g1 = new getInformation(R.drawable.p1,"p1");
           list.add(g1);
           getInformation g2 = new getInformation(R.drawable.p2,"p2");
           list.add(g2);
           getInformation g3 = new getInformation(R.drawable.p3,"p3");
           list.add(g3);
           getInformation g4 = new getInformation(R.drawable.p4,"p4");
           list.add(g4);
           getInformation g5 = new getInformation(R.drawable.p5,"p5");
           list.add(g5);
           getInformation g6 = new getInformation(R.drawable.p6,"p6");
           list.add(g6);
           getInformation g7 = new getInformation(R.drawable.p7,"p7");
           list.add(g7);
           getInformation g8 = new getInformation(R.drawable.p8,"p8");
           list.add(g8);
           getInformation g9 = new getInformation(R.drawable.p9,"p9");
           list.add(g9);
           getInformation g0 = new getInformation(R.drawable.p0,"p0");
           list.add(g0);
       }

    }

    public void login(View view){
        Intent intent  = new Intent(MainActivity.this,MainActivity2.class);
        startActivity(intent);
    }
}


class myAdapter extends RecyclerView.Adapter<myAdapter.viewHolder>{

    private  int Resources;
    private List<getInformation> list;
    public myAdapter(List list,int Resources) {
        this.list = list;
        this.Resources = Resources;
    }

    @NonNull
    @Override
    public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(Resources,parent,false);
        viewHolder holder = new viewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull viewHolder holder, int position) {
        getInformation information = list.get(position);
        holder.imageView.setImageResource(information.getImg());
        holder.textView.setText(information.getLabel());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class viewHolder extends RecyclerView.ViewHolder{

        private ImageView imageView;
        private TextView textView;

        public viewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            textView = itemView.findViewById(R.id.textView);
        }
    }

}

class getInformation{
    private int img;
    private String label;
    public getInformation(int img,String label){
        this.img = img;
        this.label = label;
    }

    public int getImg() {
        return img;
    }

    public String getLabel() {
        return label;
    }
}


class getData{
    private int Recourse;
    private String title;
    public getData(int Recourse,String title){
        this.Recourse = Recourse;
        this.title = title;
    }

    public int getRecourse() {
        return Recourse;
    }

    public String getTitle() {
        return title;
    }
}

